package com.blb.seckill.task;

import com.blb.seckill.entity.SeckillCourse;
import com.blb.seckill.service.SeckillCourseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 定时任务
 */
@Slf4j
@Component
public class SeckillCourseTask {

    @Autowired
    private SeckillCourseService seckillCourseService;

    /**
     * 30秒执行一次，凌晨开始，插入满足条件的秒杀课程到缓存中
     * Seconds Minutes Hours DayofMonth Month DayofWeek Year
     */
    @Scheduled(cron = "0/30 * * * * ?")
    public void loadCourseToRedis(){
        List<SeckillCourse> seckillCourses = seckillCourseService.loadSeckillCoursesToRedis();
        seckillCourses.forEach(seckillCourse -> {
            log.info("定时保存课程：{}",seckillCourse);
        });
    }
}
